import createDOMElement from './createDOMElement'
import unmountNode from './unmountNode'
export default function mountNativeElement(virtualDOM, container, oldDOM) {
    // 将转换后的DOM对象放置在页面中
    let newElement = createDOMElement(virtualDOM)

    // 判断oldDOM是否存在，存在则在其前面插入，不存在则追加
    if(oldDOM) {
        container.insertBefore(newElement, oldDOM)
    } else {
        container.appendChild(newElement)
    }

    // 判断oldDOM是否存在，存在则删除
    if(oldDOM) {
        unmountNode(oldDOM)
    }

    // 获取类组件的实例对象
    let component = virtualDOM.component
    if(component) {
        // 将DOM对象储存在类组件的实例对象中
        component.setDOM(newElement)
    }
}